/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.cloudminga.gui;

/**
 *
 * @author jyoti
 */



import java.io.*;
import org.jdom.output.*;
import java.io.File;
import java.util.*;







public class XmlGenerate
{


        public XmlGenerate()
        {
        }

//functiom to create an XMlFile
        public boolean XmlBackupSetView(Object [] files)
        {
            boolean status=false;
           try{

                    //String curDir = System.getProperty("user.dir");

                    //boolean dirStatus=new File(curDir+"/XmlFile").mkdir();
                    File xmlFile=new File("Xmlfile\\backupview.xml");
                    xmlFile.createNewFile();
                    FileOutputStream fos=new FileOutputStream(xmlFile);
                    createXMLFile(files,fos);
                    status=true;


                }catch(IOException ie)
                {
                   ie.printStackTrace();
                }

            return status;
        }

        
//Writes the name of File
        public void createXMLFile(Object[] files,FileOutputStream fos)
        {
            	try{



                        org.jdom.Element root=new org.jdom.Element("Files");
                        org.jdom.Document doc=new org.jdom.Document(root);
                        //Element root1=new Element("Files");
                        //Document doc1=new Document(root);
                          File[] file;//an array to store files
                          int j = 0;//initializing variables
                          Vector newFileList;
                          String path =System.getProperty("user.dir");//initialize path variable
                          file = new File(path).listFiles();/*holds filelist of the specified path*/
                          newFileList = new Vector();
                          for (int i = 0; i < file.length; i++) {
                            /*checks for file*/
                          if (file[i].isFile()) {
                       
                            String fileName =files[i].toString();
                            
                        }
                        XMLOutputter op=new XMLOutputter();
                        op.output(doc, fos);

                        newFileList.insertElementAt(file[i], j);
                        j++;

                        //op.output(doc1, fos);

                    }

		}catch(Exception ex)
                {
                   ex.printStackTrace();
                }
        
        }

        public static void main(String args[])
        {
            XmlGenerate xg=new XmlGenerate();
            TreeSet FinalList=new TreeSet();
            xg.XmlBackupSetView(FinalList.toArray());


           
        }
        }
        
             ///// xml file reader

// public ArrayList XmlFileReader(String FileName)
// {
//     ArrayList XmlFileList=new ArrayList();
//     try
//     {
//          String path=System.getProperty("user.dir")+"/XmlFile/"+FileName;
//          File file = new File(path);
//          System.out.println("Xml path :: -  "+path);
//          if(file.exists())
//          {
//
//              DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
//              DocumentBuilder db = dbf.newDocumentBuilder();
//              Document doc = db.parse(file);
//              doc.getDocumentElement().normalize();
//              NodeList nodeList=doc.getDocumentElement().getChildNodes();
//              for (int s = 0; s < nodeList.getLength(); s++)
//              {
//                  //System.out.println("File Name :: "+s+"  :: "+nodeList.item(s).getTextContent());
//                  XmlFileList.add(nodeList.item(s).getTextContent());
//              }
//          }
//          else
//          {
//              file.createNewFile();
//              //XmlFileList;
//
//          }
//
//
//
//     }catch (Exception e) {System.out.println("Error : "+e.getMessage());}
//     return XmlFileList;
//   }



   
                



	

